
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////Author: Shahab.Alishahian@gmail.com SA	
///////////////Target:The following methods are here to set them to control events.
///////////////Version:1.1
///////////////CopyRight: 2014 Noranj Co.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//*************************************************************************************************************
//******Facebook SDK setting

var appId='' ;
var accessToken='' ;
var appAccessToken='' ;
var channelUrl='' ;

if(window.location.href.indexOf("appspot") > -1){
	//JINGLEBOARD
	appId ='370960029693800' ;
	accessToken ='CAAFRYtzLt2gBAC2jtzZAOr8WjDCqk4aiEVshWUhD4zDZAdIU5HmzO190ajJ3hAYGHQwkXdji92AZBNprPPUgHkwxZCiCRQtxh3C6UXvvPTZCWngb6ntfRItdEAXZClUdZC5ZAWnSmVZC5QX6n1qtEZAizsHtZBQGouSzycbSaarxtLZAwRpelUw37Su7VfrKMzUpYL2oFvlERlC3ZCAZDZD' ;
	appAccessToken ='370960029693800|VpS3LLkPM3HWhA_QgS6izTLjqME' ;
	channelUrl ='localhost' ;
}
else{
	 //JBCLIENT
	appId='1384343251799270' ;
	accessToken='CAATrDYfFTOYBAIaqIKrdQIEskTtYCYPOJiChsmaK67diT24JazrgriZAGNfnxQ0SyqjiyHrwwBpGZC77WZBCyXSGndzVKixAiI4Urk56Q2TkvkHpM4LiHLUdoGUo6xJGZB3iuB9ZCXshaLpzBH2HcZAWB5h6QZAx55dTIVZBLrLjZCvLph7eMHjKPgb1cwBcTr2ml6JEXvfZAiuwZDZD' ;
	appAccessToken='1384343251799270|YRd1ffbp0JaVVHTJKOlSUmWan_Q' ;
	channelUrl='localhost' ;
}

//******Google APi setting 
var clientId = '913666381572.apps.googleusercontent.com'; //jb-shhb->'828062657182-a2i7dlpvhlv2uqe4f101i1430qh1thmr.apps.googleusercontent.com';
var apiKey = 'AIzaSyBrR0uxe3x6G2-ntujf9YURrfE5R9QT728'; //jb-shhb->'AIzaSyCZtTH-e9ZXKkNX07j7RzTtDttNS_JrwfQ';
var scopes = 'https://www.googleapis.com/auth/userinfo.email'; // 'https://www.googleapis.com/auth/plus.me';
var MY_API_ROOT = 'https://shhbjb.appspot.com/_ah/api';
var MY_API_VER = 'v4';
var MY_API_NAME = 'jb';

$.getScript('https://apis.google.com/js/client.js', function() {        
	  $('body').append('<p>GOOGLE API  is loaded</p>');
});

window.onload = function() {
    //gapi.client.setApiKey(apiKey);
    gapi.client.load(MY_API_NAME, MY_API_VER, null, MY_API_ROOT);
}

//*************************************************************************************************************

$(document).ready(function() {
  filterFriend($("#header"), $("#list"));
  	
  	//alert("your machine's local network IP is "+ getUID());
  	$('#jbImageUrl').val(getQueryStringParams('imageurl'));
  	$('#jbMessageLink').val(getQueryStringParams('messagelink'));
  	
    $('.imageRef').each(function(){
        $(this).attr("src",  $('#jbImageUrl').val());
    });

    $(".footerdialog").each(function(){
    	$(this).css('background-image', 'url("images/jblogo.png")');
    });
    $.cookie("friendList", null);
    $.cookie("friendListNotAllowed", null);
    $.cookie("contributorsList", null);
    
    window.fbAsyncInit = function () {
        FB.init({
            appId: appId, // App ID
            channelUrl: channelUrl, // Channel File
            status: true, // check login status
            cookie: true, // enable cookies to allow the server to access the session
            xfbml: true, // parse XFBML
            frictionlessRequests : true
        });
    };
    // Load the SDK Asynchronously
    (function (d) {
        var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
        if (d.getElementById(id)) {
            return;
        }
        js = d.createElement('script');
        js.id = id;
        js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        ref.parentNode.insertBefore(js, ref);
    } (document));
   
    $(function () {
        $('#activator').click(function () {
            $('#overlay').fadeIn('fast', function () {
                $('#jbbox'+ $('#stepvalue').val()).animate({ 'top': '160px' }, 500);  
            });
        });
       
        $('a[id*="boxclose"]').click(function () {
            $('div[id*=jbbox]').animate({ 'top': '-500px' }, 500, function () {
                $('#overlay').fadeOut('fast');
            });
        });

        $('li[id*=next]').click(function () {
            $('#jbbox' + document.getElementById("stepvalue").value).animate({ 'top': '-500px' }, 500);
            $('#stepvalue').val(parseInt($('#stepvalue').val()) + 1);
            $('#overlay').fadeIn('fast', function () {
                $('#jbbox' + ($('#stepvalue').val())).animate({ 'top': '160px' }, 500);
            });
        });

        $('li[id*=pre]').click(function () {
            $('#jbbox' + document.getElementById("stepvalue").value).animate({ 'top': '-500px' }, 500);
            $('#stepvalue').val(parseInt($('#stepvalue').val()) - 1);
            $('#overlay').fadeIn('fast', function () {
                $('#jbbox' + ($('#stepvalue').val())).animate({ 'top': '160px' }, 500);
            });
        });
    });

    // Use a button to handle authentication the first time.
    $("#getUserList").click(function(){
  	  listUser();
    });
    
    $("#sendConversion").click(function(){
  	  var list = JSON.parse($.cookie("friendList")).data ;
  	  sendBulkEmail(list);
    });
    
    $("#sendNotification").click(function(){
  	  var list = JSON.parse($.cookie("friendList")).data ;
  	  sendNotifications(list);//Sending the notification via Facebook account.
  	  saveBoard(); //After sending notification we should save the board information in Datastore.
  	  goNext();
    });
    
    $("#nextAfterPoll").click(function(){
    	sendSelectedFreind();
    	addUser();
    });
    
    $("#backToMain").click(function(){
    	 closeBox();
      });
      
    
    
});

//*************************************************************************************************************